<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php 
	$TOURNAMENT = $this->tournament_entity->init('id', intval($_GET['t_id']));
	if(!$TOURNAMENT){
		show_404();
		exit();
	}
?>
	
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 class="bold">Winners</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/winners")?>" title="Back?">Back?</a>
		</div>
		
		<div class="clrboth"></div>
		
			<div class="content">
					<?php $category_prize_array = $this->week_prize_entity->getFinishedCategoriesOfTournament($TOURNAMENT->id); ?>
					<?php if( count($category_prize_array) ) : ?>
						
						<?php foreach($category_prize_array as $cat): ?>	
							<div class="rowitem2">
								<div class="grid10" style="margin:5px;">
									<b> Weekly Prize From <?php echo sysDateTimeFormat($cat->starttime,'d/m/Y');?>
									To <?php echo sysDateTimeFormat($cat->endtime,'d/m/Y');?></b>
								</div>
							</div>
							<div class="clrboth"></div>
							<?php 
								$prize_list = $this->week_prize_entity->getArrayListOfPrize($cat->id);
							?>
							<?php foreach($prize_list as $prizeOBJ):?>
								<?php 
									$USER = $this->week_prize_entity->getUserObjectWithRank($prizeOBJ->rank,$TOURNAMENT->id,$cat->id);
									$PRIZE = $this->week_prize_entity->getPrizeObjectWithARank($prizeOBJ->rank, $cat->id);
									
									$thumb = $uname = $points = $rankicon = '';
									if($USER){
										$userInfo = $this->week_prize_entity->getPersonWithARank($prizeOBJ->rank,$TOURNAMENT->id,$cat->id);
										$points = bet_format( $userInfo['point'] );
									}
									$prizeImage = '';
									if($PRIZE){
										$prizeImage = $PRIZE->getPrizeImage();
									}
									$ext =  "style='float:left;margin-left:5px;margin-bottom:0px;margin-top:5px;margin-bottom:5px;text-align:center;'";
									$rankicon = "<img src='".thumb2($prizeImage,200,100)."' $ext />";
								?>
								<div class="rowitem2">
									<div class="grid4">
										<?php echo $rankicon;?>
									</div>
									<div class="grid3" style="margin-top:5px;margin-bottom:3px;">
										<?php if($PRIZE->getLogo()) echo thumb($PRIZE->getLogoImage(),40,20);?> <br/>
										Product Value: <?php echo $PRIZE->getValue();?> <br/>
										Rank: <?php echo $PRIZE->getRank();?> <br/>
										<?php if($USER):?>
											Points Scored: <?php echo bet_format($points);?><br/>	
											City: <?php echo $USER->getCity();?><br/>
										<?php endif;?>
										<?php if($PRIZE->getDeliveryStatus()):?>
											Delivery Status: <?php echo $PRIZE->getDeliveryStatus();?><br/>
										<?php endif;?>
										<?php if($PRIZE->getProof() AND $PRIZE->getDeliveryStatus()):?>
											<a href="<?php echo $PRIZE->getProofTargetFileUrl();?>" target="_blank" style="color:#333333;">Proof</a>
										<?php endif;?>
									</div>
									<div class="grid2">
										<div style="text-align:center;float:left;margin-top:25px;width:100%;"> 
											<?php if($USER):?>
												<?php echo thumb($USER->getMyAvatar(),40,40);?>
											<?php endif;?>
										</div> 
										<span class="bold" style="width:100%;text-align:center;float:left;"><?php if($USER) echo $USER->getUserName();?></span>
									</div>
									
										<div class="clrboth"></div>
								</div>
								<div class="clrboth"></div>
							<?php endforeach ;?>
							<div class="clrboth"></div>
							
						<?php endforeach ;?>
					 
					 <?php else: ?>
					<div class="rowitem2">	
						<div style="float:left;clear:both;padding:10px 0px 50px 10px;">
							Weekly Winners List will be updated as soon as the End of this contest.
						</div>
					</div>	
					 <?php endif;?>
			</div>	
	</div>	 
</div>
